﻿/*
 * Copyright 2010 www.wojilu.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;

namespace wojilu {

    /// <summary>
    /// 时间的工具类
    /// </summary>
    public class time {

        /// <summary>
        /// 检查 t 是否是明天
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static Boolean IsNextDay( DateTime t ) {
            DateTime now = DateTime.Now;
            TimeSpan span = now.Subtract( t );
            return ((span.TotalDays >= 1.0) || ((span.TotalDays > 0.0) && (now.Day > t.Day)));
        }

        #region 根据时间来提醒打招呼
        /// <summary>
        /// 根据时间来提醒打招呼
        /// </summary>
        /// <returns></returns>
        public static String RemindTime()
        {
            var date = DateTime.Now.Hour;
            if (date >= 23 || date < 5)
            {
                return "凌晨好！";
            }
            else if (date >= 5 && date < 11)
            {
                return "上午好！";
            }
            else if (date >= 11 && date < 14)
            {
                return "中午好！";
            }
            else if (date >= 14 && date < 19)
            {
                return "下午好！";
            }
            else
            {
                return "晚上好！";
            }
        }
        #endregion

        #region 格式化日期时间,0(yyyy-MM-dd),1(yyyy-MM-dd HH:mm:ss),2(yyyy/MM/dd),3(yyyy年MM月dd日),4(MM-dd),5(MM/dd),6(MM月dd日),7(yyyy-MM),8(yyyy/MM),9(yyyy年MM月),10(HH:mm:ss),11(yyyy-MM-dd HH:mm)
        /// <summary>
        /// 格式化日期时间,0(yyyy-MM-dd),1(yyyy-MM-dd HH:mm:ss),2(yyyy/MM/dd),3(yyyy年MM月dd日),4(MM-dd),5(MM/dd),6(MM月dd日),7(yyyy-MM),8(yyyy/MM),9(yyyy年MM月),10(HH:mm:ss),11(yyyy-MM-dd HH:mm)
        /// </summary>
        /// <param name="dateMode">显示模式</param>
        /// <returns>0-9种模式的日期</returns>
        public static string GetNow(int dateMode)
        {
            return FormatDate(DateTime.Now, dateMode);
        }

        /// <summary>
        /// 格式化日期时间,0(yyyy-MM-dd),1(yyyy-MM-dd HH:mm:ss),2(yyyy/MM/dd),3(yyyy年MM月dd日),4(MM-dd),5(MM/dd),6(MM月dd日),7(yyyy-MM),8(yyyy/MM),9(yyyy年MM月),10(HH:mm:ss),11(yyyy-MM-dd HH:mm)
        /// </summary>
        /// <param name="dateTime">日期时间</param>
        /// <param name="dateMode">显示模式</param>
        /// <returns>0-9种模式的日期</returns>
        public static string FormatDate(DateTime dateTime, int dateMode)
        {
            if (string.IsNullOrEmpty(dateTime.ToString())) return "";
            switch (dateMode)
            {
                case 0:
                    return dateTime.ToString("yyyy-MM-dd");

                case 1:
                    return dateTime.ToString("yyyy-MM-dd HH:mm:ss");

                case 2:
                    return dateTime.ToString("yyyy/MM/dd");

                case 3:
                    return dateTime.ToString("yyyy年MM月dd日");

                case 4:
                    return dateTime.ToString("MM-dd");

                case 5:
                    return dateTime.ToString("MM/dd");

                case 6:
                    return dateTime.ToString("MM月dd日");

                case 7:
                    return dateTime.ToString("yyyy-MM");

                case 8:
                    return dateTime.ToString("yyyy/MM");

                case 9:
                    return dateTime.ToString("yyyy年MM月");

                case 10:
                    return dateTime.ToString("HH:mm:ss");
                case 11:
                    return dateTime.ToString("yyyy-MM-dd HH:mm");
            }

            return dateTime.ToString();
        }
        #endregion

    }

}

